﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Collections.Generic;
using System.Linq;

namespace G.WeiBo.Converter
{
    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string str = value.ToString();
            List<string> strs = str.Split(' ').ToList();
            strs.Insert(3, strs[5]);
            strs.RemoveAt(strs.Count - 1);
            str = string.Join(" ", strs.ToArray());
            DateTime date = DateTime.Parse(str);

            if (date.Year == DateTime.Now.Year)
            {
                return date.ToString("MM月dd日 HH:mm");
            }
            else
            {
                return date.ToString("yyyy年MM月dd日 HH:mm");
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
